package kyFtp.process
{
	import kyFtp.events.FtpEvent;
	import kyFtp.request.FtpRequest;
	import kyFtp.request.FtpRequestType;
	import kyFtp.response.Response;
	import kyFtp.response.ResponseType;

	/**
	 * @author 秦家洋
	 * @E-mail: develop@kongyue.cc
	 * 创建时间：2015-7-2 下午5:49:11
	 * 
	 */
	public class LoginProcess extends ProcessBase
	{
		public var user:String;
		public var pwd:String;
		public var isLogin:Boolean;
		public function LoginProcess()
		{
			
		}
		public override function responseHandler(res:Response):void
		{
			switch(res.code)
			{
				case ResponseType.SERVICE_READY:
					if(!res.isMultiline)
						sendCmd(FtpRequest.parse(FtpRequestType.USER, user));
					break;
				case ResponseType.USER_OK:
					this.sendCmd(FtpRequest.parse(FtpRequestType.PASS, pwd));
					break;
				case ResponseType.LOGGED_IN:
					isLogin = true;
					dispatchEvent(new FtpEvent(FtpEvent.LOGIN_SUCCESS));
					break;
				default:
					isLogin = false;
					dispatchEvent(new FtpEvent(FtpEvent.LOGIN_FAIL));
			}
		}
	}
}